//
//  HLUserAcoot.swift
//  HLwWeibo
//
//  Created by hqhxu on 16/2/28.
//  Copyright © 2016年 hqhxu. All rights reserved.
//

/*
access_token 	string 	用于调用access_token，接口获取授权后的access token。
expires_in 	string 	access_token的生命周期，单位是秒数。
remind_in 	string 	access_token的生命周期（该参数即将废弃，开发者请使用expires_in）。
uid 	string 	当前授权用户的UID。

"access_token" = "2.00bMBQ8DZG_j1Da359d2aeb30qXic5";
"expires_in" = 157679999;
"remind_in" = 157679999;
uid = 3151177441;
*/
import UIKit

class HLUserAcoot: NSObject,NSCoding {

    /// 用于调用access_token，接口获取授权后的access token。
    var access_token:String?
    
    /// access_token的生命周期，单位是秒数。
    var expires_in: Double = 0 {
        didSet { //赋值后调用  再给expiresDate赋值
            expiresDate = NSDate(timeIntervalSinceNow: expires_in)
        }
    
    }
    /// 当前授权用户的UID。
    var uid:String?
    
    /// 过期日期
    var expiresDate:NSDate?
    
    ///用户头像地址（大图），180×180像素
    var avatar_large:String?
    
    /// 用户昵称
    var screen_name:String?

    
    init(dict:[String:AnyObject]) {
        
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    func encodeWithCoder(aCoder: NSCoder) {
        
        aCoder.encodeObject(access_token, forKey: "access_token")
        aCoder.encodeDouble(expires_in, forKey: "expires_in")
        aCoder.encodeObject(uid, forKey: "uid")
        aCoder.encodeObject(expiresDate, forKey: "expiresDate")
        aCoder.encodeObject(avatar_large, forKey: "avatar_large")
        aCoder.encodeObject(screen_name, forKey: "screen_name")
    }
    
    required init?(coder aDecoder: NSCoder) {
        
        access_token = aDecoder.decodeObjectForKey("access_token") as? String
        expires_in = aDecoder.decodeDoubleForKey("expires_in")
        uid = aDecoder.decodeObjectForKey("uid") as? String
        expiresDate =  aDecoder.decodeObjectForKey("expiresDate") as? NSDate
        avatar_large = aDecoder.decodeObjectForKey("avatar_large") as? String
        screen_name = aDecoder.decodeObjectForKey("screen_name") as? String
    }
    
   override var description: String {
        let keys = ["access_token","expires_in","uid","expiresDate","avatar_large","screen_name"];
        
        return "UserAcount模型:\(dictionaryWithValuesForKeys(keys).description)"
    }
    
}
